home *** CD-ROM | disk | FTP | other *** search
- Path: walrus1.walrus.com!warrenj
- From: warrenj@walrus.com (Warren Johnson)
- Newsgroups: comp.lang.c
- Subject: Memory leakage
- Date: 17 Apr 1996 16:11:46 GMT
- Organization: Intellitech Corporation
- Message-ID: <4l3582$1v@alice.walrus.com>
- NNTP-Posting-Host: walrus1.walrus.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Suppose I have a function:
-
- int give_number() {
- ...
- ...
- ...
- }
-
- and in main I have a line :
-
- if(x>give_number()) {
- ...
- ... }
-
- Now my question is this: give_number() returns an integer. Obviously
- the compiler must allocate memory for this integer. However, we are not
- returning this integer to an integer pointer, therefore this allocated
- memory is floating about in the void somewhere without something pointing
- to it. Is this memory deallocated when the function is finished running
- it's course or do i have to do this:
-
- y = give_number();
-
- if(x>y) { blabalh}
-
- free(y); // or just let y be deallocated when the function is over with
-
- ..........
- So any ideas guys? :)
-
- Btw, to all of you who posted in response to my memory allocation
- qeustion: Thank you for your help, it has been quite useful.
-
- --
- Warren D. Johnson
- CEO and Founder
- Runtime Computing, Inc.
-